<template>
  <div>
    <div id="main" style="width: 250px; height: 250px"></div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [],
    };
  },

  mounted() {
    this.getEvaluateData();
  },
  methods: {
    // 获取数据库满意度
    getEvaluateData() {
      this.$http.get(`/evaluate`).then((res) => {
        res.result.map((res) => {
          this.tableData.push({ value: res.mark, name: res.user_id });
          this.loadingChart();
          console.log(this.tableData);
        });
      });
    },
    loadingChart() {
      // 基于准备好的dom，初始化echarts实例
      var echarts = require("echarts");
      var chartDom = document.getElementById("main");
      var myChart = echarts.init(chartDom);
      var option;

      // 指定图表的配置项和数据
      option = {
        tooltip: {
          trigger: "item",
        },
        legend: {
          top: "5%",
          left: "center",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 2,
            },
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },

            data: this.tableData,
          },
        ],
      };

      // 使用刚指定的配置项和数据显示图表。
      option && myChart.setOption(option);
    },
  },
};
</script>
<style lang=scss
 scoped>
</style>
